package com.zq.widget.inverted.game.role.impl.plane;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.view.animation.LinearInterpolator;

import com.zq.widget.inverted.R;
import com.zq.widget.inverted.game.role.Role;
import com.zq.widget.inverted.game.role.RoleGroup;
import com.zq.widget.inverted.game.role.anim.Anim;
import com.zq.widget.inverted.game.role.anim.AnimProxy;
import com.zq.widget.inverted.game.role.anim.LinearPointFEvaluator;
import com.zq.widget.inverted.game.role.anim.OnAnimUpdateListener;
import com.zq.widget.inverted.game.role.anim.RepeatMode;
import com.zq.widget.inverted.game.role.damage.Damage;
import com.zq.widget.inverted.game.role.damage.DamageProxy;
import com.zq.widget.inverted.game.role.decorate.Decorator;
import com.zq.widget.inverted.game.role.decorate.HPBar;
import com.zq.widget.inverted.game.role.equipment.EquipmentRole;
import com.zq.widget.inverted.game.role.equipment.weapon.gun.BulletFactory;
import com.zq.widget.inverted.game.role.equipment.weapon.gun.bullet.Bullet;
import com.zq.widget.inverted.game.role.hp.HP;
import com.zq.widget.inverted.game.role.hp.HPProxy;
import com.zq.widget.inverted.game.role.impl.type.Enemy;

/**
 * Created by zhangqiang on 2018/4/2.
 */
public class PlaneBoss extends EquipmentRole implements HP,Damage,Enemy{

    private float x1,y1,x2,y2;
    private HP hpProxy;
    private Damage damageProxy;
    private Decorator hpBar;

    public PlaneBoss(Context context, float x1, float y1, float x2, float y2) {
        super(context, R.drawable.img_plane_boss);
        this.x1 = x1 + bounds().width()/2;
        this.y1 = y1;
        this.x2 = x2 - bounds().width()/2;
        this.y2 = y2;
        hpProxy = new HPProxy(200);
        damageProxy = new DamageProxy(100);
        hpBar = new HPBar(1, Color.RED,20,10,hpProxy);
    }

    @Override
    protected Anim<?> onCreateAnim() {
        return AnimProxy.ofPointF(new PointF(x1,y1),new PointF(x2,y2))
                .setOnAnimUpdateListener(new OnAnimUpdateListener<PointF>() {
                    @Override
                    public void onAnimUpdate(Anim<PointF> anim) {
                        updateLocation(anim.getAnimateValue());
                    }
                })
                .setInterpolator(new LinearInterpolator())
                .setRepeatCount(-1)
                .setRepeatMode(RepeatMode.REVERSE)
                .setDuration(5000)
                .setTypeEvaluator(new LinearPointFEvaluator());
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        hpBar.onDraw(canvas,bounds());
    }

    @Override
    public void onCollisionWith(@NonNull Role target) {
        super.onCollisionWith(target);
    }

    @Override
    public boolean isFinish() {
        return super.isFinish() || getHp() <= 0;
    }

    @Override
    public long totalHp() {
        return hpProxy.totalHp();
    }

    @Override
    public long getHp() {
        return hpProxy.getHp();
    }

    @Override
    public boolean addHp(long hp) {
        return hpProxy.addHp(hp);
    }

    @Override
    public boolean reduceHp(long hp) {
        return hpProxy.reduceHp(hp);
    }

    @Override
    public long damage() {
        return damageProxy.damage();
    }
}
